#include "Test.Application.h"

#undef  APP_NAME
#define APP_NAME	TestSprite
#undef  APP_BASE
#define APP_BASE	TestApp


class APP_NAME : public APP_BASE
{
protected:
	Sprite2DPtr			sprite;
	Sprite2D::Instance	spriteInst;

public:
	APP_NAME (IPlatform *platform, EDevice::type deviceType) :
		APP_BASE( platform, deviceType )
	{}

	void Update (float dt) override
	{
		TestApp::Update( dt );

		ESS()->GetGraphicsEngine()->GetViewport()->Apply();
		ESS()->GetGLStateManager()->ClearColor( color4f( 0.0f ) );
		
		sprite->Update( spriteInst, dt );
		sprite->Draw( rect( -0.5f, -0.5f, 0.5f, 0.5f ), spriteInst );

		batch.Flush();
		batch.Clear();
		
		ESS()->GetGraphicsEngine()->SwapBuffers();
	}

	void OnEnter () override
	{
		APP_BASE::OnEnter();

		ESS()->GetResourceManager()->Load( EResource::SPRITE_2D, "spr/sprite0.spr", sprite );

		sprite->SetAnimation( spriteInst, 0 );
	}

	void OnExit () override
	{
		sprite = null;
		APP_BASE::OnExit();
	}
};